//
//  CircleDetailArticleTableViewCell.m
//  GLGW_Shoping
//
//  Created by whx on 2018/12/12.
//  Copyright © 2018年 yang. All rights reserved.
//

#import "CircleDetailArticleTableViewCell.h"

@implementation CircleDetailArticleTableViewCell
{
    GLGWImageView *imgVV;
    GLGWLabel *detailLab;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.contentView.backgroundColor = [UIColor whiteColor];
        
        GLGWImageView *imagV = [[GLGWImageView alloc] initInSuperView:self.contentView];
        [imagV mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(@(kWidthProportion_In_iPhoneTriploid(16)));
            make.top.equalTo(@(kHeightProportion_In_iPhoneTriploid(18)));
            make.width.height.equalTo(@(kWidthProportion_In_iPhoneTriploid(44)));
        }];
        imagV.backgroundColor = kRandomColor;
        imagV.layer.masksToBounds = YES;
        imagV.layer.cornerRadius = 22;
        imgVV = imagV;
        
        GLGWLabel *label = [[GLGWLabel alloc] initWithFont:SYSTEMFONT(14) theColor:[UIColor colorWithHexString:@"#A89A60"] inSuperView:self.contentView];
        [label mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(@(kHeightProportion_In_iPhoneTriploid(15)));
            make.left.equalTo(imagV.mas_right).offset(kWidthProportion_In_iPhoneTriploid(10));
            make.right.equalTo(self.contentView.mas_right).offset(-kWidthProportion_In_iPhoneTriploid(140));
            make.height.equalTo(@(kHeightProportion_In_iPhoneTriploid(20)));
        }];
        label.text = @"陈也";
        //
        GLGWLabel *label2 = [[GLGWLabel alloc] initWithFont:SYSTEMFONT(14) theColor:kColor_Rule_Black inSuperView:self.contentView];
        [label2 mas_updateConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(imagV.mas_left);
            make.top.equalTo(imagV.mas_bottom).offset(kHeightProportion_In_iPhoneTriploid(11));
            make.right.equalTo(@(-kWidthProportion_In_iPhoneTriploid(15)));
            make.bottom.equalTo(@(-kHeightProportion_In_iPhoneTriploid(26))).priorityMedium();
        }];
        label2.text = @"为什么要卖啊么要卖啊么要卖啊么要卖啊么要卖啊么要卖啊么要卖啊么要卖啊么要卖啊么要卖啊？";
        label2.numberOfLines = 0;
        detailLab = label2;
        
        GLGWLabel *label3 = [[GLGWLabel alloc] initWithFont:SYSTEMFONT(12) theColor:[UIColor colorWithHexString:@"#999999"] inSuperView:self.contentView];
        [label3 mas_updateConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.contentView.mas_right).offset(-kWidthProportion_In_iPhoneTriploid(15));
            make.centerY.equalTo(label.mas_centerY);
            make.width.equalTo(@(110));
            make.height.equalTo(@(17));
        }];
        label3.text = @"2018-09-25 12:00";
        
        [self setSepartionLineWith:lineModel_Half];
    }
    return self;
}

- (void)replyAction:(GLGWButton *)sender
{
    if (self.BlockReply) {
        self.BlockReply(sender);
    }
}

- (void)likeAction:(GLGWButton *)sender
{
    if (self.BlockLike) {
        self.BlockLike(sender);
    }
}

- (void)refreshPhoto:(NSInteger)num
{
    GLGWView *baV = [[GLGWView alloc] initWithInSuperView:self.contentView];
    CGFloat he = kHeightProportion_In_iPhoneTriploid(111) * 3 + kHeightProportion_In_iPhoneTriploid(8);
    [baV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self->detailLab.mas_bottom).offset(kHeightProportion_In_iPhoneTriploid(11));
        make.left.equalTo(self.mas_left).offset(kWidthProportion_In_iPhoneTriploid(15));
        make.right.equalTo(self.mas_right).offset(-kWidthProportion_In_iPhoneTriploid(15));
        make.height.equalTo(@(he));
    }];
    
    CGFloat viewW = kWidthProportion_In_iPhoneTriploid(112);
    CGFloat viewH = kHeightProportion_In_iPhoneTriploid(111);
    int cols = 3;
    // 列间距
    CGFloat colMargin = kWidthProportion_In_iPhoneTriploid(4);
    //行间距
    CGFloat rowMargin = kHeightProportion_In_iPhoneTriploid(5);

    CGFloat maxH = 0.0;
    for (int i = 0; i < num; i ++) {
        NSUInteger col = i % cols;
        CGFloat viewX = col * (viewW + colMargin);
        NSInteger row = i / cols;
        CGFloat viewY = row * (viewH + rowMargin);
        GLGWButton *btn = [[GLGWButton alloc] initInSuperView:baV];
        btn.frame = CGRectMake(viewX, viewY, viewW, viewH);
        btn.backgroundColor = kRandomColor;
        btn.tag = 560 + i;
        [btn addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
        if (i == num - 1) {
            maxH = viewY + viewH;
        }
    }
    [baV mas_updateConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(@(maxH));
    }];
    [detailLab mas_updateConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(@(- kHeightProportion_In_iPhoneTriploid(26) - maxH));
    }];
}

- (void)btnAction:(GLGWButton *)sender
{
    
}

@end
